<?php
require_once('Team.php');
require_once('functions.php');

/*******************************************************************************************************/
    function getTeams($InputID, $League)
    {
		switch ($League)
		{
		case "NFL"://National Football League
			$num_of_teams = 32;
			break;
		case "AFL"://Arena Football League
			$num_of_teams = 17;
			break;
		}
		
		//Connect To Database
		$query = "SELECT * FROM ".$League."QuickPicks WHERE UserID=$InputID";
		$Outsideresult = mysql_query($query) or die("Cannot query the database.<br/>");
		$OutsideRow = mysql_fetch_array($Outsideresult);
		for($num = 0; $num < $num_of_teams; $num++)
		{
			if ($OutsideRow["Team".($num+1)] != "")
			{
				$query = "SELECT * FROM ".$League."Teams WHERE TeamName='".$OutsideRow["Team".($num+1)]."'";
				$result = mysql_query($query) or die("Cannot query the database.<br/>");
				$myrow = mysql_fetch_array($result);
				# 					   Team($TeamName='',$City='',$URL='',$Wins='',$HomeWins='',$RoadWins='',$AFCWins='',$NFCWins='',$DivWins='',$Losses='',$HomeLosses='',$RoadLosses='',$AFCLosses='',$NFCLosses='',$DivLosses='',$Ties='',$Conference='',$Division='',$PointsFor='',$PointsAgainst='',$Streak='')
				$TeamList[$num] =& new Team($myrow["TeamName"],$myrow["City"],$myrow["URL"],$myrow["Wins"],$myrow["HomeWins"],$myrow["RoadWins"],$myrow["AFCWins"],$myrow["NFCWins"],$myrow["DivWins"],$myrow["Loses"],$myrow["HomeLosses"],$myrow["RoadLosses"],$myrow["AFCLosses"],$myrow["NFCLosses"],$myrow["DivLosses"],$myrow["Ties"],$myrow["Conference"],$myrow["Division"],$myrow["PointsFor"],$myrow["PointsAgainst"],$myrow["Streak"]);
			}
		}

		//Return The List
        return $TeamList;         
    }
    
    
/*******************************************************************************************************/    
    function processPickOrder($key,$inputID,$League)
    {	
		#$weeknum = checkWeekBounds(getWeek());
		
		/*
        if (!isset($_POST[$key]) || !is_array($_POST[$key]))
			return;
		
        # Highest Rank (first pick) is worth the maximum amount for the week.
		# I.E. 
		#	If there are 16 games this week pick #1 is worth 16 points, pick #16 is worth 1 point.
		#	If there are 14 games this week pick #1 is worth 14 points, pick #14 is worth 1 point.
 		*/
        $ranking = count($key);
        foreach ($key as $GameNum)
        {
            #$SQL = "UPDATE ".$League."Picks SET Game".$GameNum."Rank=".$ranking." WHERE (Week = ".checkWeekBounds(getWeek())." AND UserID=".$inputID.")";
            $SQL = "UPDATE ".$League."Picks SET Game".$GameNum."Rank=".$ranking." WHERE (Week=2 AND UserID=1)";
			echo "$SQL<br/>";
			mysql_query($SQL) or die("Cannot query the database.<br/>");
            $ranking--;
        }
    }
?>